package com.hzhr.iot.log.service;

import com.hzhr.iot.log.convertor.custom.LogCustomConvertor;
import com.hzhr.iot.log.dao.LogDao;
import com.hzhr.iot.log.entity.LogEntityWithBLOBs;
import com.hzhr.iot.log.model.log.LogModel;
import com.hzhr.iot.log.model.log.LogPostModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LogService {
    @Autowired
    LogCustomConvertor logCustomConvertor;
    @Autowired
    LogDao logDao;

    public LogModel post(LogPostModel body) {
        //新增模型转实体
        LogEntityWithBLOBs withBLOBs = logCustomConvertor.postModel2withBLOBs(body);
        if (withBLOBs.getExceptionInfo() != null) {
            withBLOBs.setExistException("1");
        }
        //新增
        logDao.insert(withBLOBs);
        //实体转模型
        LogModel result = logCustomConvertor.withBLOBs2model(withBLOBs);
        //返回
        return result;
    }
}
